<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" />
    <title>区域基站导入</title>
    <link href="../../layui/css/layui.css" rel="stylesheet" type="text/css">
    <link href="../../css/style.css" rel="stylesheet" type="text/css">
    <link href="../../layui/css/iconfont/iconfont.css" rel="stylesheet" type="text/css">
    <script src="../../layui/layui.js"></script>
    <script src="../../js/jquery-1.8.3.js"></script>
    <script src="../../js/util.js"></script>
    <script type="text/javascript">

        layui.use(['form', 'layer', 'jquery', 'element', 'upload'], function () {
            var table = layui.table;
            var form = layui.form;
            var $ = layui.$;
            var layer = layui.layer;
            var upload = layui.upload;
            var user;
            upload.render({
                elem: '#import'
                , url: '/smsBaseStation/upload'
                , auto: false //关闭自动上传
                , accept: 'file' //普通文件
                , exts: 'csv' //只允许上传csv文件
                //,multiple: true
                , bindAction: '#upload'
                , before: function (obj) {
                    this.data = {
                        cityId: $('#cityId').val(),
                        mgrId: $('#mgrId').val()
                    }
                    layer.load(); //上传loading
                }
                , done: function (obj) {
                    layer.closeAll('loading'); //关闭loading
                    if (obj.code == 0) {
                        var data=obj.data;
                        var num= data.toString().split(",");
                        layer.open({
                            title: '导入成功'
                            , content: '成功导入' + data[0] + '个区域,' +  data[1] + '个基站'
                        });
                    }
                    if (obj.code > 0) {
                        layer.msg(obj.msg);
                    }

                }
                , error: function (index, upload) {
                    layer.closeAll('loading'); //关闭loading
                    layer.msg("上传过程中出现异常，请重试");
                }

            });


            //身份识别
            $(document).ready(function () {
                $.ajax({
                    type: 'post',
                    async: false,
                    url: '/util/findUser',
                    success: function (json) {
                        user = json;
                        if (json.duty == 1) {
                            $("#cityId").val(json.cityId);
                            $("#cityId").attr("disabled", true);
                            var data = selectMgrInfo(json.cityId);
                            appendMgr(data);
                            form.render();
                        } else if (json.duty == 2) {
                            $("#cityId").val(json.cityId);
                            $("#cityId").attr("disabled", true);
                            appendMgr(json.list);
                            form.render();
                        }
                    }, error: function () {
                        layer.msg('系统异常，请联系管理员处理!');
                    }
                });
            });

            //根据城市ID查询项目
            function selectMgrInfo(cityId) {
                var data;
                var url = '/util/findByCityId?cityId=' + cityId;
                $.ajax({
                        type: 'post',
                        async: false,
                        url: url,
                        success: function (json) {
                            data = json.data;
                        }, error: function () {
                            layer.msg('系统异常，请联系管理员处理!');
                        }
                    }
                );
                return data;
            }  //监听项目
            form.on('select(cityId)', function (data) {
                var data = selectMgrInfo(data.value);
                appendMgr(data);
            });
            form.on('select(mgrId)', function (data) {
                if (!isNull($('#mgrId').val())) {
                    $("#upload").attr("class", "layui-btn");
                    $("#upload").attr("disabled", false);
                    form.render();
                } else {
                    $("#upload").attr("class", "layui-btn layui-btn-disabled");
                    $("#upload").attr("disabled", true);
                    form.render();
                }
            });

            //动态拼接项目
            function appendMgr(data) {
                if (data.length != null) {
                    var options = '<option value="">请选择</option>';
                    for (var i = 0; i < data.length; i++) {
                        options += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
                    }
                    $('#mgrId').html(options);
                } else {
                    $('#mgrId').html('<option value="">该地市下没有项目</option>');
                }
                form.render();
            }

        });
    </script>
</head>
<body>
<div class="layui-content-body">
    <div class="scroll-box">
        <div class="breadcrumb-box">
                <span class="layui-breadcrumb" lay-separator="|">
                     <a href="javascript:returnIndex2()">首页&nbsp;</a>
                  <a href="stationManage.html">区域基站导入管理</a>
                  <a href="">区域基站导入&nbsp;</a>
                </span>
        </div>
        <div class="content-box">
            <div class="form-select-box">
                <div class="layui-form layui-form-pane">
                    <div class="layui-upload">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">省份</label>
                            <div class="layui-input-block">
                                <input type="text" name="province" lay-verify="required" value="江苏"
                                       autocomplete="off" class="layui-input" disabled>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">地市</label>
                            <div class="layui-input-block">
                                <select id="cityId" name="cityId" lay-filter="cityId" id="cityId">
                                    <option value="">请选择</option>
                                    <option value="11">苏州</option>
                                    <option value="12">淮安</option>
                                    <option value="13">宿迁</option>
                                    <option value="14">南京</option>
                                    <option value="15">连云港</option>
                                    <option value="16">徐州</option>
                                    <option value="17">常州</option>
                                    <option value="18">镇江</option>
                                    <option value="19">无锡</option>
                                    <option value="20">南通</option>
                                    <option value="21">泰州</option>
                                    <option value="22">盐城</option>
                                    <option value="23">扬州</option>
                                    <option value="25">省级</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">项目名称</label>
                            <div class="layui-input-block">
                                <select name="mgrId" lay-filter="mgrId" id="mgrId">
                                    <option value="">请先选择地市</option>
                                </select>
                            </div>
                        </div>
                    </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <button type="button" class="layui-btn" id="import"><i class="layui-icon"></i>区域基站导入</button>
                                </div>
                                <br class="layui-form-item">
                                    <span><a href="/smsBaseStation/apidownload"><u>基站导入帮助手册</u></a></span></br>
                                    <span><a href="/smsBaseStation/modeldownload"><u>基站导入模板下载</u></a></span>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <button type="button" class="layui-btn layui-btn-disabled" id="upload" disabled="true">导入
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div>
                    <h4 class="tips-h4"><i class="iconfont icon-xinxi"></i>提示：基站信息以呈批文件为准！支持重新导入
                    </h4>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
</html>